package controllers

import (
	"fmt"
	"github.com/kataras/iris"
	"github.com/kataras/iris/mvc"
	"go.mongodb.org/mongo-driver/bson/primitive"
	"imooc-product/datamodels"
	"imooc-product/services"
)

type ProductController struct {
	Ctx iris.Context
	ProductService services.IProductService
}

func (p *ProductController)GetAll()mvc.View  {
	productArray,_:= p.ProductService.GetAllProduct()
	return mvc.View{
		Name: "product/view.html",
		Data: iris.Map{
			"productArray":*productArray[0],
		},
	}
}
func (p *ProductController)GetCreate(){
	var data datamodels.Product
	data.ID,_ = primitive.ObjectIDFromHex("123")
	data.ProductImage = "123.png"
	data.ProductName = "加湿器"
	data.ProductNum = 12
	data.ProductUrl = "www.huochaiqi.com"
	insertresult,err :=p.ProductService.InsertProduct(&data)
	if err !=nil{
		fmt.Println(err)
		return
	}
	fmt.Println(insertresult)
}
